#include "相交链表.h"
struct ListNode* getIntersectionNode(struct ListNode* headA, struct ListNode* headB) {
	if (headA == NULL || headB == NULL)
	{
		return NULL;
	}
	//走到这里两个链表都不为空
	ListNode* curA = headA, * curB = headB;
	int A = 1,B = 1;
    //计算两个链表的节点个数
	while (curA->next)
	{
		curA = curA->next;
		A++;
	}
	while (curB->next)
	{
		curB = curB->next;
		B++;
	}
	int gap = abs(A - B);//绝对值
	ListNode* longlist = headA, * shortlist = headB;
	if (A < B)
	{
		longlist = headB, shortlist = headA;//假设法
	}
    //调整longlist的位置，能在后续操作时让两链表在同一起始比较位置上进行处理
	while (gap)
	{
		longlist = longlist->next;
		gap--;
	}
	while (longlist)
	{
		if (longlist == shortlist)
			return longlist;
		longlist = longlist->next;
		shortlist = shortlist->next;
	}
	return NULL;
}